﻿using System;
using System.Linq;
using System.Text;

namespace RazakiSite.UserControls
{
    public partial class UCInfo : BaseUserControl
    {
        #region >>>PROPERTY<<<

        public string Text { set { SetText(value); } }

        public EInfoType InfoType { set { SetType(value); } }

        public bool Hide { set { PnlMain.Visible = !value; } }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        private void SetText(string text)
        {
            StringBuilder result = new StringBuilder();
            string seperator = string.Empty;

            if (text.Contains("<ul>")) //bullet
                seperator = "<ul>";
            else if (text.Contains("<ol>")) //number
                seperator = "<ol>";

            if (!string.IsNullOrWhiteSpace(seperator))
            {
                result.Append(seperator);

                var sentences = text.Split(new string[] { seperator }, StringSplitOptions.RemoveEmptyEntries);
                sentences.ToList().ForEach(x => result.Append(string.Format("<li>{0}</li>", x)));

                result.Append(seperator.Replace(seperator, "</ul>").Replace(seperator, "</ol>"));
            }
            else
            {
                result.Append(text);
            }

            LtrText.Text = result.ToString();
        }

        private void SetType(EInfoType infoType)
        {
            PnlMain.CssClass = "ContainerInfo";
            PnlMain.CssClass += string.Format(" ContainerInfo_{0}", infoType);

            ImgIcon.ImageUrl = string.Format("~/Images/Info/{0}.png", infoType);
            ImgIcon.AlternateText = infoType.ToString();
        }

    }
}